package com.tankgame;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: FENGYiMing
 * @Date: 2024/04/02/14:16
 * @Description: 子弹射击
 */
public class Shot implements Runnable {
    private int x;
    private int y;
    private int direction;
    private int speed = 5;
    private boolean isLive = true;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direct) {
        this.direction = direct;
    }

    public int getSpeed() {
        return speed;
    }

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direction = direct;
    }

    @Override
    public void run() {
        /*
          根据不同的方向进行射击，子弹开始移动
         */
        while (true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            switch (direction) {
                case 0:
                    y -= speed;
                    break;
                case 1:
                    x += speed;
                    break;
                case 2:
                    y += speed;
                    break;
                case 3:
                    x -= speed;
                    break;
                default:
                    break;
            }
            if (!(x >= 0 && x <= 900 && y >= 0 && y <= 650 && isLive)) {
                isLive = false;
                break;
            }
        }
    }
}
